<!-- 实名认证页面 -->
<template>
	<view class="head">
		<view class="msg">
			  <view class="item">
				<view class="i1">姓名:</view>
				<u-input  v-model="data.realName" :clearable="false" input-align="right" type="text" placeholder="请输入姓名 " />
			  </view>
			  <view class="item">
				<view class="i1">身份证号码:</view>
				<u-input  v-model="data.identityCard" :clearable="false" input-align="right" type="text" placeholder="请输入身份证号码 " />
			  </view>
		</view>
		<view style="margin-top: 40rpx;">
			<u-button type="success" @click="real">提交验证</u-button>
		</view>
		<u-toast ref="uToast" position="center" />
		<u-modal v-model="show" :content="content" @confirm="confirm" :show-cancel-button="showBut"></u-modal>
	</view>
</template>

<script>
	import {realNameData} from '@/api/user.js'
	import {getCode, wx_login} from "@/api/login";
	export default {
		data() {
			return {
				show:false,
				content:"",
				data:{
				    realName: "",
				    identityCard: ""
				}
			}
		},
		methods: {
			real(){
				this.show = true
				this.content = "是否提交实名认证"
			},
			async confirm(){
				const res = await realNameData(this.data)
				if(res.data.code === 200){
					this.$refs.uToast.show({
						title:res.data.data,
						type:"success"
					})
					const {code} = await getCode()
					const loginMsg = await wx_login(code)
					if (loginMsg.data.msg != '用户不存在') {
						uni.setStorageSync('realName',loginMsg.data.data.isAttestation);
					}
					uni.navigateBack({
						delta:1
					})
					return
				}
				if(res.data.code === 500){
					this.$refs.uToast.show({
						title:res.data.msg,
						type:"error"
					})
				}
			}
		}
	}
</script>

<style>
.head{
	padding: 20rpx;
	width: 80%;
	box-shadow: rgba(99, 99, 99, 0.2) 0px 2px 8px 0px;
	border-radius: 20rpx;
	margin: 120rpx auto;
	color: #c9c9c9;
}
 .msg{
	  color: black;
	  display: flex;
	  flex-direction: column;
	  border-radius: 20rpx;
}
.item{
	display: flex;
	justify-content: space-between;
	align-items: center;
	padding: 30rpx;
	font-size: 26rpx;
}
.i1{
	white-space: nowrap;
}
</style>
